package com.cdream.basic.algorithm.leetcode.tree;

public class Question110 {
    public boolean isBalanced(TreeNode root) {
        if (root==null){
            return true;
        }
        int bal = treeHigh(root.left) - treeHigh(root.right);
        return bal <= 1 && bal >= -1 && isBalanced(root.left) && isBalanced(root.right);
    }

    public int treeHigh(TreeNode node) {
        if (node == null) {
            return 0;
        }
        return Math.max(treeHigh(node.left), treeHigh(node.right))+1;
    }
}
